package com.socket.client;

import java.net.InetAddress;
import java.net.Socket;

public class Main {
	public static void main(String[] args) throws Exception {

		// 地址和端口号
		Socket s = new Socket(InetAddress.getByName(Constants.IP),
				Integer.parseInt(Constants.PORT));
		ClientActionController controller = new ClientActionController(s);

		boolean flag = true;
		boolean isEnd;
		boolean isfirstSendOk = false;
		// 头部信息
		while (true) {

			try {
				if (!isfirstSendOk) {
					System.out.println("执行");
					controller.sendHeadInfo(Constants.FILE_DIR + "123.pdf");
					isfirstSendOk = true;
				}
				if (!flag) {
					System.out.println("有错误发生");
					Thread.sleep(100000);
					isEnd = controller.receiveActionAfterError();
					flag = true;
				} else {
					isEnd = controller.receiveAction();
				}

			} catch (SocketException e) {
				System.out.println(e.log);
				flag = false;
				continue;
			}
			if (isEnd) {
				controller.close();
				s.close();
				System.out.println("结束 ");
				break;
			}
		}

	}
}
